//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package SaveServlet.teacher;

import com.lyq.bean.Elective;
import com.lyq.bean.Student;
import com.lyq.bean.service.TC_Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet({"/Grade_Servlet"})
public class Grade_Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public Grade_Servlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String cNo;
        if (id.equals("grade")) {
            cNo = request.getParameter("cNo");
            String sNo = request.getParameter("sNo");
            
            // 添加调试信息
            System.out.println("Grade_Servlet: cNo=" + cNo + ", sNo=" + sNo);
            
            new Elective();
            Elective e = (new TC_Service()).getElective(cNo, sNo);
            
            // 添加调试信息
            System.out.println("Grade_Servlet: elective object=" + e);
            if (e != null) {
                System.out.println("Grade_Servlet: cNo=" + e.getcNo() + ", sNo=" + e.getsNo() + 
                                   ", cName=" + e.getcName() + ", sName=" + e.getsName());
            }
            
            request.getSession().setAttribute("e", e);
            request.getRequestDispatcher("/jsp/teacher/t/Grade.jsp").forward(request, response);
        } else if (id.equals("seekall")) {
            cNo = (String)request.getSession().getAttribute("UNAME");
            System.out.println("Grade_Servlet: cNo=" + cNo);
            new ArrayList();
            List<Student> list = (new TC_Service()).SeekAllMyStudent(cNo);
            request.setAttribute("list", list);
            request.getRequestDispatcher("/jsp/teacher/t/MyStudents.jsp").forward(request, response);
        }

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String seek;
        String name;
        String tNo;
        if (id.equals("grade")) {
            new Elective();
            Elective e = (Elective)request.getSession().getAttribute("e");
            seek = e.getcNo();
            name = e.getsNo();
            tNo = request.getParameter("grade");
            Boolean bool = (new TC_Service()).grade(seek, name, tNo);
            if (bool) {
                request.getSession().setAttribute("message", "评分成功！");
            } else {
                request.getSession().setAttribute("message", "评分失败！");
            }

            request.getRequestDispatcher("Message.jsp").forward(request, response);
        } else if (id.equals("seek")) {
            String select = request.getParameter("select");
            seek = request.getParameter("seek");
            name = request.getParameter("name");
            tNo = (String)request.getSession().getAttribute("UNAME");
            new ArrayList();
            List<Student> list = (new TC_Service()).SeekMyStudent(tNo, select, seek, name);
            if (list.size() > 0) {
                request.setAttribute("list", list);
                request.getRequestDispatcher("jsp/teacher/t/MyStudents.jsp").forward(request, response);
            } else {
                request.getSession().setAttribute("message", "未搜索到结果！");
                request.getSession().setAttribute("url", "Grade_Servlet?id=seekall");
                response.sendRedirect("Message.jsp");
            }
        }

    }
}
